package com.zouma.service;

import com.zouma.pojo.Test;
import jxl.Sheet;
import jxl.Workbook;

import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: serein
 * @DateTime: 2021/7/9 9:30
 * @Description:
 */
public class TestService {
    /**
     * 查询指定目录中电子表格中所有的数据
     * @param file 文件完整路径
     * @return
     */
    public static List<Test> getAllByExcel(String file){
        List<Test> list=new ArrayList<Test>();
        try {
            Workbook rwb=Workbook.getWorkbook(new File(file));
            Sheet rs=rwb.getSheet(0);//或者rwb.getSheet(0)
            int clos=rs.getColumns();//得到所有的列
            int rows=rs.getRows();//得到所有的行

            System.out.println(clos+" rows:"+rows);
            for (int i = 1; i < rows; i++) {
                for (int j = 0; j < clos; j++) {
                    //第一个是列数，第二个是行数
                    String id= rs.getCell(j++, i).getContents();//默认最左边编号也算一列 所以这里得j++
                    String occurrenceDate = rs.getCell(j++, i).getContents();
                    String securityName = rs.getCell(j++, i).getContents();
                    String securityCode = rs.getCell(j++, i).getContents();
                    String dealVolume = rs.getCell(j++, i).getContents();
                    String capitalOccurCount = rs.getCell(j++, i).getContents();
                    String dealPrice = rs.getCell(j++, i).getContents();
                    String dealMoney = rs.getCell(j++, i).getContents();
                    String innerCapitalAccount = rs.getCell(j++, i).getContents();
                    String businessCategory = rs.getCell(j++, i).getContents();
                    String exchangeCurrency = rs.getCell(j++, i).getContents();
                    String exchangeCode = rs.getCell(j++, i).getContents();
                    String assetLiabCategory = rs.getCell(j++, i).getContents();
                    String marketCode = rs.getCell(j++, i).getContents();
                    String productCode = rs.getCell(j++, i).getContents();



                    System.out.println("id:"+id+"occurrenceDate:"+occurrenceDate+"securityName:"+securityName+"securityCode:"
                            +securityCode+"dealVolume"+dealVolume);

                    list.add(new Test(id,occurrenceDate,securityName,securityCode,dealVolume,capitalOccurCount,dealPrice,dealMoney,innerCapitalAccount
                    ,businessCategory,exchangeCurrency,exchangeCode,assetLiabCategory,marketCode,productCode));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;

    }
}
